﻿using SqlSugar.Extensions;
using Sunny.UI;
using System.Drawing;

namespace CoreShop.App
{
    public partial class UIReturnItem2 : UIUserControl
    {
        public UIReturnItem2()
        {
            InitializeComponent();
        }

        private Color selectedColor = Color.FromArgb(255, 192, 128);
        public Color SelectedColor
        {
            get => selectedColor;
            set
            {
                selectedColor = value;
                Invalidate();
            }
        }

        public string DishName
        {
            get => lblName.Text;
            set => lblName.Text = value;
        }

        public string UnitName
        {
            get => lblUnitName.Text;
            set => lblUnitName.Text = value;
        }

        public string SpecName
        {
            get => lblSpecName.Text;
            set => lblSpecName.Text = value;
        }

        public string Number
        {
            get => lblNumber.Text;
            set => lblNumber.Text = value;
        }

        public string Price
        {
            get => lblPrice.Text;
            set => lblPrice.Text = value;
        }

        public string RefundQuantity
        {
            get => txtRefundQuantity.Text;
            set => txtRefundQuantity.Text = value;
        }

        public decimal MaxNumber
        {
            get => txtRefundQuantity.Maximum.ObjToDecimal();
            set => txtRefundQuantity.Maximum = (double)value;
        }

        public string Amount
        {
            get => lblAmount.Text;
            set => lblAmount.Text = value;
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            if (Number.ObjToDecimal(0) > txtRefundQuantity.Text.ObjToDecimal(0))
            {
                txtRefundQuantity.Text = (RefundQuantity.ObjToDecimal(0) + 1).ToString();
                Invalidate();
            }
        }

        private void btnCut_Click(object sender, System.EventArgs e)
        {
            if (txtRefundQuantity.Text.ObjToDecimal(0) > 0)
            {
                txtRefundQuantity.Text = (RefundQuantity.ObjToDecimal(0) - 1).ObjToDecimal(0).ToString();
                Invalidate();
            }
        }

        private void UIReturnItem2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (txtRefundQuantity.Text.ObjToDecimal(0) > 0)
            {
                e.Graphics.FillRectangle(SelectedColor, 0, 0, Width, Height);
                txtRefundQuantity.BackColor = SelectedColor;
            }
            else
            {
                txtRefundQuantity.BackColor = Color.White;
            }
        }

        private void lblRefundQuantity_TextChanged(object sender, System.EventArgs e)
        {
            Invalidate();
        }
    }
}
